package org.lql.chaos.kafka.example.partition;

import org.apache.kafka.common.Cluster;
import org.lql.chaos.kafka.example.enums.PartitionEnum;

import java.util.Random;

/**
 * @author: liangqinglong
 * @date: 2025-08-10 13:11
 * @description: 随机分区策略
 **/
public class RandomPartitionStrategy implements CustomPartitionStrategy {

	private final Random random = new Random();

	@Override
	public String getName() {
		return PartitionEnum.RANDOM.getName();
	}

	@Override
	public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
		return random.nextInt(cluster.partitionCountForTopic(topic));
	}
}
